package com.sdy.hospitalguard.web.mq.config;

import com.sdy.hospitalguard.biz.constants.MqConstants;
import com.sdy.hospitalguard.web.websocket.WebsocketEventConsumer;
import com.sdy.mq.base.BaseMessageListener;
import com.sdy.mq.config.RocketMqConfig;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConsumerGroupConfig {
    @Autowired
    private RocketMqConfig rocketMqConfig;
    @Autowired
    private WebsocketEventConsumer websocketEventConsumer;
    @Value("${res.app.load-balance-index:0}")
    private Integer loadBalanceIndex;

    @Bean
    public DefaultMQPushConsumer websocketEventListener() throws Exception {
        return rocketMqConfig.createConsumerGroup("consumer_group_hospital_guard_ws_event_" + loadBalanceIndex,
                new BaseMessageListener(websocketEventConsumer), MqConstants.Topics.TOPIC_HOSPITAL_GUARD,
                MqConstants.Tags.TAG_WS_EVENT);
    }
}
